<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\stat;

use app\enum\CommonEnum;
use app\enum\ServiceCostEnum;
use app\service\BaseService;
use app\service\stat\cdc\QqAdvertiserCostStatService;

final class StatMediaService extends BaseService
{
    private static array $handle = [];

    private function __construct()
    {
    }

    private function __clone()
    {
    }

    /**
     * 获取实例.
     * @return mixed|StatMediaService
     */
    public static function getInstance(int $mediaId = 0, int $type = 0)
    {
        $key = md5($mediaId . $type);
        if (! isset(self::$handle[$key])) {
            if ($type == ServiceCostEnum::TASK_TYPE_ACCOUNT) {
                if ($mediaId == CommonEnum::OE_MEDIA) {
                    self::$handle[$key] = new OeAdvertiserStatService();
                }
                if ($mediaId == CommonEnum::KS_MEDIA) {
                    self::$handle[$key] = new KsAdvertiserStatService();
                }
                if ($mediaId == CommonEnum::QQ_MEDIA) {
                    self::$handle[$key] = new QqAdvertiserStatService();
                }
            } elseif ($type == ServiceCostEnum::TASK_TYPE_VIDEO) {
                if ($mediaId == CommonEnum::OE_MEDIA) {
                    self::$handle[$key] = new OeVideoStatService();
                }
                if ($mediaId == CommonEnum::KS_MEDIA) {
                    self::$handle[$key] = new KsVideoStatService();
                }
                if ($mediaId == CommonEnum::QQ_MEDIA) {
                    self::$handle[$key] = new QqVideoStatService();
                }
            } elseif ($type == ServiceCostEnum::TASK_TYPE_PICTURE) {
                if ($mediaId == CommonEnum::OE_MEDIA) {
                    self::$handle[$key] = new OePicStatService();
                }
                if ($mediaId == CommonEnum::KS_MEDIA) {
                    self::$handle[$key] = new KsPicStatService();
                }
                if ($mediaId == CommonEnum::QQ_MEDIA) {
                    self::$handle[$key] = new QqPicStatService();
                }
            }
        }
        return self::$handle[$key];
    }
}
